/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import fever.utils.Stringifier;
import fever.utils.StringUtil;

/**
 * Defines available methods for FileSystem context.
 * 
 * @see fever.app.context.ContextManager
 *
 * @author Romain Ecarnot
 */
class fever.app.context.abstract.FileSystem
{
	//-------------------------------------------------------------------------
	// Public Properties
	//-------------------------------------------------------------------------
	
	/** Template method. Indicates if passed-in {@code path} is a directory or not. */
	public var isDirectory : Function;

	/** Template method. Creates new directory. */
	public var createDirectory : Function;

	/** Template method. Removes passed-in directory. */
	public var deleteDirectory : Function;

	/** Template method. Renames passed-in directory. */
	public var renameDirectory : Function;

	/** Template method. Indicates if passed-in {@code path} is a valid file. */
	public var isFile : Function;

	/** Template method. Renames passed-in file. */
	public var renameFile : Function;

	/** Template method. Removes passed-in file. */
	public var deleteFile : Function; 

	/** Template method. Reads passed-in file content ( Binary mode is not supported ! ). */
	public var readFile : String;

	/** Template method. Writes text data into passed-in file ( Binary mode is not supported ! ). */
	public var writeToFile : Function;

	/** Template method. Appends text data into passed-in file ( Binary mode is not supported ! ). */
	public var appendToFile : Function;
	
	/** Template method. Returns user "temporary" directory  from current system. */
	public var getTempDirectory : Function; 
	
	/** Template method. Returns current application path from current system. */
	public var getAppDirectory : Function;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Returns is filesystem is ready.
	 * 
	 * <p>Only really use by SharedObject and Server filesystem.
	 */
	public function isAvailable() : Boolean
	{
		return true;
	}
	
	/**
	 * Builds a correct full qualified filename with passed-in {@code directory} and 
	 * {@code filename}.
	 * 
	 * <p>Example, getFullQualifiedFileName( 'temp', 'test.txt ) return temp/test.txt.
	 */
	public function getFullQualifiedFileName( directory : String, filename : String ) : String
	{
		var d : String = StringUtil.finishWithChar( directory, '/', true );
		return d + filename;
	}
	
	/**
	 * Returns string representation.
	 */
	public function toString() : String
	{
		return Stringifier.parse( this );
	}
	
		
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	private function FileSystem()
	{
		
	}	
}